package com.fanwh.healthycampus2.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.fanwh.healthycampus2.R;
import com.fanwh.healthycampus2.bean.HealthyInformation;

import java.util.List;

public class InformationAdapter extends RecyclerView.Adapter<InformationAdapter.ViewHolder> {
    private List<HealthyInformation> mHealthyInformationList;


    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView studentName;
        TextView studentId;
        TextView school;
        TextView temperature;
        TextView date;

        public ViewHolder(View view){
            super(view);
            studentId = view.findViewById(R.id.item_studentID);
            studentName = view.findViewById(R.id.item_name);
            school = view.findViewById(R.id.item_school);
            temperature = view.findViewById(R.id.item_temperature);
            date = view.findViewById(R.id.item_date);
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item, parent, false);
        final ViewHolder holder = new ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        HealthyInformation healthyInformation = mHealthyInformationList.get(position);
        holder.studentName.setText(healthyInformation.getName());
        holder.studentId.setText(healthyInformation.getStudentID());
        holder.date.setText(healthyInformation.getDate());
        holder.school.setText(healthyInformation.getSchool());
        holder.temperature.setText(healthyInformation.getTemperature()+"℃");
    }

    @Override
    public int getItemCount(){
        return mHealthyInformationList.size();
    }

    public InformationAdapter(List<HealthyInformation> healthyInformationList){
        mHealthyInformationList = healthyInformationList;
    }
}
